 package com.gmrz.uaf.common.service.challengestore;
 
 import com.gmrz.service.challengestore.IChallengeData;
 import java.io.Serializable;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 import java.util.Random;

 import com.gmrz.util.Convert;
 import com.google.common.primitives.Bytes;
 import com.google.common.primitives.Longs;
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 public class UAFChallengeData implements Serializable, IChallengeData {

   private static final long serialVersionUID = -2856306299545700126L;
   private final String key_;
   private int retryCount_;
   private static final Logger LOG = LogManager.getLogger(UAFChallengeData.class);
 
   public UAFChallengeData(byte[] challenge, long timestamp) {
     this.retryCount_ = 0;
     this.key_ = createKey(challenge, timestamp);
   }
 
   public String getKey() {
     return this.key_;
   }
 
   private String createKey(byte[] nonce, long creationTimestamp) {

       try {
       return UAFChallengeStoreUtil.createChallengeDataKey(nonce, creationTimestamp);
     }
     catch (Exception ex) {
       LOG.error("Error creating challenge data key ", ex);
     }return null;
   }

   public int getCount() {
     return this.retryCount_;
   }
 
   public int incrementCount() {
     return ++this.retryCount_;
   }
 
   public int hashCode() {
     int prime = 31;
     int result = 1;
     result = 31 * result + (this.key_ == null ? 0 : this.key_.hashCode());
     return result;
   }
 
   public boolean equals(Object data) {

     if (data == null)
       return false;
     if ((data instanceof UAFChallengeData)) {
       UAFChallengeData otherData = (UAFChallengeData)data;
       if (this.key_ == null) {
         if (otherData.key_ != null)
           return false;
       }
       else return this.key_.equals(otherData.key_);
     }
     return false;
   }

 }
